export * from "./hooks/use-mount";
export * from "./hooks/use-async";
export * from "./hooks/use-array";

/**
 * 把传入的字符串转换成数字
 * @param {string} value
 * @returns {boolean}
 */
export const toNumber = (value: unknown) => isNaN(Number(value)) ? 0 : Number(value);

/**
 * 判断传入值是否为空
 * @param {unknown} value
 * @returns {boolean}
 */
export const isVoid = (value: unknown) =>
  value === undefined || value === null || value === "";

/**
 * 清除对象内为空的键
 * 如果不传返回 {}
 * @param {object} object
 * @returns {object}
 */
export const cleanObject = (object?: { [key: string]: unknown }) => {
  if (!object) return {};
  const o = { ...object };
  Object.keys(o).forEach((key) => {
    if (isVoid(o[key])) delete o[key];
  });
  return o;
};
